package com.woorigil.social.domain.point;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.woorigil.social.domain.CouponSqlMapDaoSupport;
import com.woorigil.social.domain.ProviderCode;
import com.woorigil.social.domain.deal.ManageStatus;

@Repository
public class DealPointDao extends CouponSqlMapDaoSupport<DealPoint, Integer> {
	public static final String NAMESPACE = "DealPoint";

	@Override
	public String getNamespace() {
		return NAMESPACE;
	}

	@SuppressWarnings("unchecked")
	public List<DealPoint> search(DealPointCondition condition) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "search"), condition);
	}

	public int updateClickCount(int dealId, int clickCount) {
		Map<String, Object> parmas = new HashMap<String, Object>();
		parmas.put("dealId", dealId);
		parmas.put("clickCount", clickCount);
		return getSqlMapClientTemplate().update(getStatementName(NAMESPACE, "updateClickCount"), parmas);
	}
	
	public int updateOrderNo(int dealId, int orderNo) {
		Map<String, Object> parmas = new HashMap<String, Object>();
		parmas.put("dealId", dealId);
		parmas.put("orderNo", orderNo);
		return getSqlMapClientTemplate().update(getStatementName(NAMESPACE, "updateOrderNo"), parmas);
	}
	
	public void updateStatus(ProviderCode providerCode, ManageStatus manageStatus) {
		Map<String, Object> parmas = new HashMap<String, Object>();
		parmas.put("providerCode", providerCode);
		parmas.put("manageStatus", manageStatus);
		getSqlMapClientTemplate().update(getStatementName(NAMESPACE, "updateStatus"), parmas);
	}

	public void deleteByManageStatus(ProviderCode providerCode, ManageStatus manageStatus) {
		Map<String, Object> parmas = new HashMap<String, Object>();
		parmas.put("providerCode", providerCode);
		parmas.put("manageStatus", manageStatus);
		getSqlMapClientTemplate().delete(getStatementName(NAMESPACE, "deleteByManageStatus"), parmas);
	}

	public List<Integer> selectDeadIds() {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "selectDeadIds"));
	}

	public DealPoint selectByDealId(int dealId) {
		return (DealPoint)getSqlMapClientTemplate().queryForObject(getStatementName(NAMESPACE, "selectByDealId"), dealId);
	}
}